<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 扩展运算符 ...
    // 1.合并数组
    let arr = [1, 2, 3]
    let arr1 = [4, 5]

    let res = [...arr, ...arr1]
    console.log(res);

    // 2. 展开数组
    let arr2 = [12, 456]
    console.log(Math.max(...arr2));

    // 3. 展开对象
    // 合并对象，合并配置
    let obj1 = { name: "张三" };
    let obj2 = { age: 20 };
    var obj = { ...obj1, ...obj2 };
    console.log(obj); // {name: '张三', age: 20}

    // 4.展开字符串
    let str = "abcdefg";
    let arr3 = [...str];
    console.log(arr3); // ['a', 'b', 'c', 'd', 'e', 'f', 'g']


    // 5. 处理伪数组和参数
    function fn () {
      console.log(arguments);
      // 5.1 通过 Array.from 来把伪数组转成数组
      //  var arr =  Array.from(arguments);
      //  console.log(arr);
      // 5.2 通过展开运算符 来转换
      var arr = [...arguments];
      console.log(arr);
    }
    fn(1, 2, 3);

    // 处理不定参数 ，rest剩余参数
    // 不定参
    function fn (a, ...args) {
      // console.log(arguments);
      console.log(args);
      console.log(a);
    }

    fn(1, 2, 3, 4);



  </script>
</body>

</html>